package com.zbkj.service.service.impl;

import com.wechat.pay.java.core.Config;
import com.wechat.pay.java.core.RSAAutoCertificateConfig;
import com.wechat.pay.java.service.payments.jsapi.JsapiService;
import com.wechat.pay.java.service.payments.jsapi.model.Amount;
import com.wechat.pay.java.service.payments.jsapi.model.Payer;
import com.wechat.pay.java.service.payments.jsapi.model.PrepayRequest;
import com.wechat.pay.java.service.payments.jsapi.model.PrepayResponse;


/** Native 支付下单为例 */
public class QuickStart {


    public static String merchantId = "1703251424";

    public static String privateKeyPath = "D:\\WXCertUtil\\cert\\1703251424_20250113_cert\\apiclient_key.pem";

    public static String merchantSerialNumber = "4FAA87FB6246F4B3520CF2406E7F0CC319774DA7";

    public static String apiV3Key = "8i2j1sft554w6jbzfvz6flo6m50y9ji7";

    public static String notifyUrl = "https://amaptestapi.xiangddt.com/wxPay/callBack";

   public static void main(String[] args) {
        // 使用自动更新平台证书的RSA配置
        // 一个商户号只能初始化一个配置，否则会因为重复的下载任务报错
        Config config =
                new RSAAutoCertificateConfig.Builder()
                        .merchantId(merchantId)
                        .privateKeyFromPath(privateKeyPath)
                        .merchantSerialNumber(merchantSerialNumber)
                        .apiV3Key(apiV3Key)
                        .build();
        JsapiService service = new JsapiService.Builder().config(config).build();

        PrepayRequest request = new PrepayRequest();
        Amount amount = new Amount();
        amount.setTotal(100);
        request.setAmount(amount);
        request.setAppid("wx80f88562cdec3996");
        request.setMchid(merchantId);
        request.setDescription("测试商品标题");
        request.setNotifyUrl(notifyUrl);
        request.setOutTradeNo("out_trade_no_001_ouoioio");
        Payer payer = new Payer();
        payer.setOpenid("oHWpi488PiG5g_G3Z7GJ_fTLmFvU");
        request.setPayer(payer);
        PrepayResponse response = service.prepay(request);
        System.out.println(response.getPrepayId());
    }

}
